<template>
	<view class="container">
		<!-- 顶部背景 -->
		<view class="top-bg">
			<!-- 左侧：用户头像 -->
			<view class="user-pic">
				<image :src="userInfo.avatar" v-if="isAuth && userInfo.avatar!= null"></image>
				<uni-icons v-else type="person" size="50"></uni-icons>
			</view>
			<!-- 右侧：用户信息 -->
			<view class="user-info" v-if="isAuth">
				<text>用户名：{{userInfo.userName}}</text>
			</view>
			<view class="user-info" v-else @click="navTo('/pages/personal/login')">未登录</view>
		</view>
		<view class="user-menu">
			<uni-list>
				<uni-list-item :show-extra-icon="true" showArrow :extra-icon="extraIcon1" title="订单管理" />
				<uni-list-item :show-extra-icon="true" showArrow :extra-icon="extraIcon2" title="地址管理" />
				<uni-list-item :show-extra-icon="true" showArrow :extra-icon="extraIcon3" title="我的收藏" />
				<uni-list-item :show-extra-icon="true" clickable  @click="navTo('/pages/personal/set')" showArrow :extra-icon="extraIcon4" title="设置" />
			</uni-list>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				extraIcon1: {
					color: '#4cd964',
					size: '22',
					type: 'map-filled'
				},
				extraIcon2: {
					color: '#329142',
					size: '22',
					type: 'location-filled'
				},
				extraIcon3: {
					color: '#00aaff',
					size: '22',
					type: 'star-filled'
				},
				extraIcon4: {
					color: '#ff557f',
					size: '22',
					type: 'gear'
				},
			}

		},
		computed: {
			...mapState(['isAuth','userInfo']),
		},
		methods: {
			navTo(url) {
				if (this.isAuth) { 
					uni.navigateTo({url:url})
				} else {
					uni.navigateTo({"url":'/pages/personal/login'})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		.top-bg {
			height: 500upx;
			background: #00aa7f;
			display: flex;
			align-items: center;

			.user-pic {
				width: 150upx;
				height: 150upx;
				border-radius: 50%;
				background: #9caaa5;
				margin: 0 30upx 0 40upx;
				text-align: center;
				line-height: 150upx;

			}

			.user-info {
				font-size: 35upx;
				color: #fff;
				flex: 1
			}
		}

		.user-menu {
			background: #fff;
			margin: 5upx 20upx;
		}
	}
</style>